package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Car;
import com.tianqu.tms.www.car.controller.CarStockCountDetailController;
import com.tianqu.tms.www.car.viewhelper.CarStockCountListTopViewhelper;
/**
 * 库存统计车辆进出库查看
 * 
 * @author Jiazheng Sun
 *
 */
public class CarStockCountInOutAction extends TmsAction {

	private static final String MEMID = "memid";
	private static final String SERIAL = "serial";
	private static final String CARSCORE = "carScore";

	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response,UserContext uc) throws Exception {

		//
		String memid = "";
		String serial = "";
		String carScore = "";
		CarStockCountListTopViewhelper view = new CarStockCountListTopViewhelper();
		
		if(request.getParameter(MEMID) != null) {
			memid = request.getParameter(MEMID);
		} else {
			memid = (String)uc.getAttribute(MEMID);
		}
		
		if(request.getParameter(SERIAL) != null) {
			serial = request.getParameter(SERIAL);
		} else {
			serial = (String)uc.getAttribute(SERIAL);
		}
		
		if(request.getParameter(CARSCORE) != null) {
			carScore = request.getParameter(CARSCORE);
		} else {
			carScore = (String)uc.getAttribute(CARSCORE);
		}
		
		uc.removeAttribute(MEMID);
		uc.setAttribute(MEMID, memid);
		
		uc.removeAttribute(SERIAL);
		uc.setAttribute(SERIAL, serial);
		
		uc.removeAttribute(CARSCORE);
		uc.setAttribute(CARSCORE, carScore);
		
		CarStockCountDetailController controller = new CarStockCountDetailController();
//		controller.execute(uc);
		controller.record(uc);
		view = (CarStockCountListTopViewhelper)uc.getAttribute(TmsConstants.VIEWHELP);
		
		request.setAttribute(TmsConstants.VIEWHELP, view);
		uc.removeAttribute(TmsConstants.VIEWHELP);
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
